﻿using Entity.Finance.DTO.IncomeAccount;
using Entity.Finance.DTO.IncomeAccountItem;
using Entity.Finance.DTO.IncomeManage;
using Entity.Finance.View.IncomeAccount;
using Entity.Finance.View.IncomeAccountItem;
using FrameWork.Request;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Service;
using Service.System;

namespace AnQinManagermentBackendAPI.Controller.Finance
{
    /// <summary>
    /// 收款单
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    [AllowAnonymous]
    public class IncomeAccountsController : ControllerBase
    {
        /**
         * 业务接口
         */
        private readonly IncomeAccountService _service;

        /**
         * 构造函数注入
         */
        public IncomeAccountsController(IncomeAccountService service)
        {
            _service = service;
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        [HttpGet]
        [ProducesResponseType(typeof(IncomeAccountView), 200)]
        public async Task<IActionResult> GetIncomeAccountList([FromQuery] IncomeAccountSearchDTO model)
        {
            var response = await _service.GetIncomeAccountList(model);
            return StatusCode(response.Status, response);
        }
        
        /// <summary>
        /// 获取子单列表
        /// </summary>
        [HttpGet("Item")]
        [ProducesResponseType(typeof(IncomeAccountItemView), 200)]
        public async Task<IActionResult> GetIncomeAccountItemList([FromQuery] IncomeAccountItemSearchDTO model)
        {
            var response = await _service.GetIncomeAccountItemList(model);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 新增
        /// </summary>
        [HttpPost]
        public async Task<IActionResult> AddIncomeAccount([FromBody] IncomeAccountAddDTO model)
        {
            var response = await _service.AddIncomeAccount(model);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 发起收款 创建收款单
        /// </summary>
        [HttpPost("Income")]
        public async Task<IActionResult> Income(IncomeManageAddDTO model)
        {
            var response = await _service.Income(model);
            return StatusCode(response.Status, response);
        }
        
        /// <summary>
        /// 删除
        /// </summary>
        [HttpDelete]
        public async Task<IActionResult> DeleteIncomeAccount([FromQuery] string Id)
        {
            var response = await _service.DeleteIncomeAccount(Id);
            return StatusCode(response.Status, response);
        }

    }
}
